package com.suian.spring.task.config;

import com.suian.spring.task.QuartzTask;
import com.suian.spring.task.QuartzTaskMyjob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail quartzJobDetailOne() {
        return JobBuilder.newJob(QuartzTask.class)
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger quartzJobTriggerOne() {
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInSeconds(5)
                .repeatForever();

        return TriggerBuilder.newTrigger()
                .forJob(quartzJobDetailOne())
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail quartzJobDetailTwo() {
        return JobBuilder.newJob(QuartzTaskMyjob.class)
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger quartzJobTriggerTwo() {
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInSeconds(5)
                .repeatForever();

        return TriggerBuilder.newTrigger()
                .forJob(quartzJobDetailTwo())
                .withSchedule(scheduleBuilder)
                .build();
    }

}
